#coding=utf-8
#Boa:Frame:FramePurOrderShow

import wx

import DlgPopupSupplier

from product import *
from ctrlAider import *
from MyListCtrl import *

def create(parent):
    return FramePurOrderShow(parent)

[wxID_FRAMEPURORDERSHOW, wxID_FRAMEPURORDERSHOWNB, 
] = [wx.NewId() for _init_ctrls in range(2)]

class FramePurOrderShow(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAMEPURORDERSHOW,
              name=u'FramePurOrderShow', parent=prnt, pos=wx.Point(228, 77),
              size=wx.Size(1052, 693), style=wx.DEFAULT_FRAME_STYLE,
              title=u'\u91c7\u8d2d\u5355\u636e\u660e\u7ec6')
        self.SetClientSize(wx.Size(1044, 659))
        self.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Arial'))
        self.SetBackgroundColour(wx.Colour(183, 209, 173))
        self.Center(wx.BOTH)
        self.Bind(wx.EVT_CLOSE, self.OnFramePurOrderShowClose)

        self.nb = wx.Notebook(id=wxID_FRAMEPURORDERSHOWNB, name=u'nb',
              parent=self, pos=wx.Point(0, 0), size=wx.Size(1044, 659),
              style=0)
        self.nb.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnNbNotebookPageChanged,
              id=wxID_FRAMEPURORDERSHOWNB)

    def __init__(self, parent):
        self._init_ctrls(parent)

        self.myInit()
        
    def myInit(self):
        import PanelSaleList, PanelFund
        import PanelProduct
        
        # 令父窗口随子窗口一同出现
        import kit
        kit.conShow(self)
        
        [self.iPageSaleList,self.iPageFund, self.iPageDetail] = [i for i in range(3)] 
        
        self.pageShare = [self.iPageSaleList,self.iPageFund, self.iPageDetail]
        self.lastPeer = None
        
        self.panelSaleList = PanelSaleList.PanelSaleList(self.nb, PanelSaleList.Type_Pur)
        self.nb.AddPage(imageId=-1, page=self.panelSaleList, select=True,
                    text=u'采购单据')

        self.panelFund = PanelFund.PanelFund(self.nb, PanelFund.Type_Supplier)
        self.nb.AddPage(imageId=-1, page=self.panelFund, select=False,
                    text=u'往来账务')

        self.panelDetail = PanelProduct.PanelProduct(self.nb, 
                                    PanelProduct.TypePurchase, bSelect=False)
        
        self.nb.AddPage(imageId=-1, page=self.panelDetail, select=False,
                    text=u'采购明细')

    def OnFramePurOrderShowClose(self, event):
        #self.popupWin.Show(False)
        self.Show(False)

    def OnNbNotebookPageChanged(self, event):
        oldPage = event.GetOldSelection()
        newPage = event.GetSelection()
        #if(oldPage != -1 and newPage != -1 and oldPage != self.iPageTemp and newPage != self.iPageTemp):
        #print (oldPage, newPage, self.pageShare, self.lastPeer, )
        if (oldPage in self.pageShare):
            self.lastPeer = self.nb.GetPage(oldPage).getSelectPeer()
            
        if (self.lastPeer and newPage in self.pageShare):
            self.nb.GetPage(newPage).setSelectPeer(self.lastPeer)        
        event.Skip() # 必须保留这个，否则页面无法呈现

    

    

